import random
from datetime import datetime, timedelta

import clickhouse_connect

connect_info = {
    'port': 8123,
    'host': '192.168.103.43',
    'username': 'admin',
    'password': '@Abcd1234',
    'database': 'saas'
}
client = clickhouse_connect.get_client(**connect_info)
column_list = ['log_id', 'log_time', 'name', 'master_account_name', 'master_org_code', 'master_org_name', 'report_time',
               'add_time', 'expire_time', 'effect_time', 'last_login_time', 'master_account_status', 'task_sn',
               'rule_sn', 'rule_code']
table_name = 'dar_account_local'
num = 0
insert_data = []
master_org_code_list = ['193', '821', '197', '903', '561', '767', '1113', '185', '1177', '183']
rule_sn_list = ['10141600602', '10141600601', '10141600603']
rule_code_dict = {
    '10141600602': 'AR-US1600602',
    '10141600601': 'AR-US1600601',
    '10141600603': 'AR-US1600603'
}
while num < 60:
    log_id = str(random.randint(10 ** 17, 10 ** 19))
    now_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    log_time = datetime.strptime(now_time, '%Y-%m-%d %H:%M:%S')
    name = '阎婕'
    master_account_name = 'hx_yanjie'
    master_org_code = random.choice(master_org_code_list)
    master_org_name = '管理系统运营室'
    yesterday = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')
    report_time = datetime.strptime(yesterday, '%Y-%m-%d %H:%M:%S')
    master_account_status = '正常'
    task_sn = '4022503066500018'
    rule_sn = random.choice(rule_sn_list)
    rule_code = rule_code_dict[rule_sn]
    insert_data.append([log_id, log_time, name, master_account_name, master_org_code, master_org_name, report_time,
                        log_time, log_time, log_time, log_time, master_account_status, task_sn, rule_sn, rule_code])
    num += 1
client.insert(table_name, insert_data, column_names=column_list)
client.close()
